#include <QtGui>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>

#include "./include/search.h"

Search::Search(QWidget *parent)
    : QDialog(parent)
{

}

void Search::PageSeqInc()
{
    if(pageSeq == maxPageSeq)
    {
        qDebug() << "最后一页";
    }
    else
    {
        pageSeq++;
        SearchItems();
    }
}

void Search::PageSeqDes()
{
    if(pageSeq == 1)
    {
        qDebug() << "已到首页";
    }
    else
    {
        pageSeq--;
        SearchItems();
    }
}


int Search::GetMaxPages()
{
    maxPageSeq = numOfTotalItem / ITEM_NUM_OF_PERPAGE + 1;
    return maxPageSeq;
}

int Search::GetNumOfTotalItem(const QString &sqlQuery)
{
    int numOfTotalItemTemp = 0;

    QSqlDatabase::database().transaction();
    QSqlQuery query;
    query.exec(QString("select id from itemInfo where %1").arg(sqlQuery));
    qDebug() << QString("select id from itemInfo where %1").arg(sqlQuery);
    while(query.next())
    {
        numOfTotalItemTemp++;
    }

    QSqlDatabase::database().commit();


    return numOfTotalItemTemp;
}
